package developer.笔试题.打印圣诞树;

/**
 * @author zhangyongkang
 * @time 2025/8/12 14:43
 * @description
 */
public class PringChrismastTree {

    public static void main(String[] args) {
        printTop(5);
        System.out.println();
        printBottom(5);
    }

    private static void printBottom(int c) {
        //打印尾部
        //如果是单数打印中间的两边
        //如果是双数则打印中间的两个
        boolean isOd = c % 2 == 0;
        int start, end;
        if (isOd) {
            start = c / 2;
            end = start + 1;
        } else {
            start = c / 2;
            end = start + 2;
        }
        for (int i = 1; i <= 3; i++) {
            for (int j = 1; j <= c; j++) {
                if(j==start||j==end){
                    System.out.print("|");
                }else{
                    System.out.print("  ");
                }
            }
            System.out.println();
        }
    }

    private static void printTop(int c) {

        for (int i = 1; i <= c; i++) {
            System.out.println("");//每行打印一个换行符
            //打印左侧的空格
            for (int j = i; j < c; j++) {
                System.out.print(" ");
            }

            for (int j = 1; j <= i; j++) {//打印实际的
                System.out.print("* ");
            }
        }

    }
}
